
#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint16_t fetch_and_and_2(volatile uint16_t *, uint16_t, ...)
    asm("__sync_fetch_and_and_2");

uint16_t
fetch_and_and_2(volatile uint16_t *addr, uint16_t val, ...)
{
	uint16_t old, new;

	do {
		old = *addr;
		new = old & val;
	} while (atomic_cas_16(addr, old, new) != old);
	return old;
}

__strong_alias(__atomic_fetch_and_2,__sync_fetch_and_and_2)
